#!/bin/sh

#ifconfig eth0 192.168.0.2 netmask 255.255.0.0
#route add default gw 192.168.0.1
#mount -t nfs -o nolock 192.168.0.1:/nfs/rootfs /mnt

#/sbin/modprobe ide-cd
dd if=/Test.fat of=/dev/rd/0
mount -t vfat /dev/rd/0 /mnt/rd
swapon /mnt/rd/swap.img

/sbin/modprobe sata_mars&

/sbin/modprobe mmc_core
/sbin/modprobe mmc_block
/sbin/modprobe rtk_sd&

#rm -f /usr/local/etc/dvdplayer/VenusSetup.dat
mkdir /var/run	#hcy added 1
ln -s /dev/cdroms/cdrom0 /dev/cdrom0
ln -s /dev/cdrom0 /dev/dvd
ln -s /mnt/dvdvr /dev/dvdvr

# This variable tells DvdPlayer the firmware URL for internet updating
export LIVEUPDATE_URL=
export use_ipad_useragent=yes
DEFAULT_AP_DIR=/usr/local/bin
touch /tmp/command_sender.txt
if [ -f $DEFAULT_AP_DIR/DvdPlayer ] && [ -x $DEFAULT_AP_DIR/DvdPlayer ]; then
	cd $DEFAULT_AP_DIR
	if [ -f $DEFAULT_AP_DIR/RootApp ] && [ -x $DEFAULT_AP_DIR/RootApp ]; then
		echo Running dvdplayer with RootApp
		tail -f /tmp/command_sender.txt |./RootApp DvdPlayer&
	else
		echo Running dvdplayer
		tail -f /tmp/command_sender.txt |./DvdPlayer&
	fi
else
    echo 1 > /sys/realtek_boards/reclaim_dvr
	/etc/dvdplayer/script/run_tail
fi

#Nand doesn't have signature
#SIGNATURE=`dd if=/dev/mtdblock/0 bs=8 count=1`
#if [ "$SIGNATURE" != "VERONA__" ]; then
#	echo This is not the first time booting up. No need to write the magic into flash
#	let size="0x"`grep mtd3 /proc/mtd | cut -d " " -f2`
#	let size=size-0x120000
#	let size=size+130816
#	let size=size/4
#	MAGIC=`dd if=/dev/mtdblock/3 bs=4 skip=$size count=1`
#	if [ "$MAGIC" = "babe" ]; then
#		echo This is not the first time booting up. No need to write the magic into flash
#	else
#		dd if=/usr/local/etc/magic of=/dev/mtdblock/3 bs=4 seek=$size count=1
#		echo This is the first time booting up. Write the magic into flash
#	fi
#fi

echo 2 /tmp/hdd/volumes/HDD1/ > /sys/realtek_boards/misc_operations

sleep 30 && swapon /dev/sda2
for i in /opt/etc/init.d/S??* ;do
	$i  &
done

mount -o bind /usr/local/etc/menu.rss /usr/local/bin/scripts/menu.rss
